﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RepRef;
using System.Configuration;

public partial class ContentPages_Dashboard : System.Web.UI.Page
{
    IsimpleWcfClient repProxy;
    RepRef.StatisticsReport ststReport;
    RepRef.ModuleManager modMgr;
    string strXMLPath;

    public string rptXMLpath
    {
        get
        {
            string _rptpath = string.Empty;
            if (Session["RptXMLPath"] != null)
            {

                _rptpath = Session["RptXMLPath"].ToString();
            }
            else
            {
                if (Request.QueryString["rptLink"] != string.Empty)
                {
                    _rptpath = Request.QueryString["rptLink"].ToString();
                }
            }
            return _rptpath;
        }
    }

    public string ProjectName
    {
        get
        {
            string _projName = string.Empty;
            if (Session["ProjName"] != null)
            {
                _projName = Convert.ToString(Session["ProjName"]);
            }
            else
            {
                _projName = ConfigurationManager.AppSettings["ProjName"].ToString();
            }
            return _projName;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        lblprojName.Text = this.ProjectName; 
        if (!IsPostBack)
        {
            if (Session["RptXMLPath"] != null)
            {
                strXMLPath = Session["RptXMLPath"].ToString();
            }
            else
            {
                if (Request.QueryString["rptLink"] != string.Empty)
                {
                    strXMLPath = Request.QueryString["rptLink"].ToString();
                    Session["RptXMLPath"] = strXMLPath;
                }
            }
            //LoadApplicationStatistics(strXMLPath);
            //LoadAppCoverageClassLevel(strXMLPath);
            LoadApplicationStatistics(strXMLPath);
            LoadAppCoverageClassLevel(strXMLPath);

            //InitParameters="PageID=1"

           // sltCvgDistn.InitParameters = "PageID=1,rptLink=" + strXMLPath;
            if (Request.QueryString != null)
            {
                string str = string.Empty;
            }
        }
    }

    protected void LoadApplicationStatistics(string strXMLPath)
    {
        try
        {
            repProxy = new IsimpleWcfClient();
            modMgr = repProxy.ParseXmlObject(strXMLPath);
            ststReport = repProxy.GetStatetics(strXMLPath);
           
            lblCovLines.Text = ststReport.LOC.ToString();
            lblParCovLines.Text = ststReport.PLOC.ToString();
            //lblCovClasses.Text = ststReport
            lblCovBlocks.Text = ststReport.BlocksCov.ToString();
            lblNCLines.Text = ststReport.NCLOC.ToString();
            lblNCBlocks.Text = ststReport.BlocksNt.ToString();
            lblStatsName.Text = this.ProjectName;
            lblCovClasses.Text = modMgr.CoveredClsCount.ToString();
            lblNClasses.Text = modMgr.NCoverdClsCount.ToString();
            lblMethodsPerClass.Text = string.Format("{0:#.##}", modMgr.AvgMethodClass);
            lbltotcls.Text = modMgr.TotalClasses.ToString();
            lblTime.Text = modMgr.FileCreationTime.ToString();
        }
        catch (Exception ex)
        {
        }

    }
    protected void LoadAppCoverageClassLevel(string strXMLPath)
    {
        string strCovPer = string.Empty;
        int intMajor = 0;
        int intMinor = 0;
        try
        {
            repProxy = new IsimpleWcfClient();
            modMgr = repProxy.ParseXmlObject(strXMLPath);
            lblCoverage.Text = modMgr.CoveredClsCount.ToString();
            strCovPer = modMgr.classCoveragePercentage.ToString();
            if (strCovPer == "100")
            {
                strCovPer = strCovPer + ".00";
                lblCoveragePercent.Text = strCovPer.Substring(strCovPer.IndexOf('.') - 3, 6) + " %";
            }
            else
            {
                lblCoveragePercent.Text = strCovPer.Substring(strCovPer.IndexOf('.') - 2, 5) + " %";
            }

            if (strCovPer != string.Empty)
            {
                //string tempMajor;
                //if (strCovPer == "100.00")
                //{
                //    tempMajor = strCovPer.Substring(strCovPer.IndexOf('.') - 3, 6);
                //}
                //else
                //{
                //    tempMajor = strCovPer.Substring(strCovPer.IndexOf('.') - 2, 5);
                //}

                string[] tempArr = strCovPer.Split('.');
                if (tempArr.Length != 0)
                {
                    intMajor = Convert.ToInt16(tempArr[0]);
                }
                intMinor = 100 - intMajor;

                lblMajorPercent.Width = intMajor * 2;
                lblMinorPercent.Width = intMinor * 2;
                pnlProgress.Width = ((intMajor * 2) + (intMinor * 2)) + 1;
            }
        }
        catch (Exception ex)
        {
        }
    }
}
